﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using MyAspNetCoreTodo.Datas;
using MyAspNetCoreTodo.Dtos;
using MyAspNetCoreTodo.Identity;
using MyAspNetCoreTodo.Models;
using MyAspNetCoreTodo.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreTodo.UnitTests
{
    public class TodoItemServiceShould
    {
        [Fact]
        public async Task AddNewItemAsIncompleteWithDueDate()
        {
            var options = new DbContextOptionsBuilder<ApplicationDbContext>()
              .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;
            // Set up a context (connection to the "DB") for writing
            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                var fakeUser = new ApplicationUser
                {
                    Id = "fake-000",
                    UserName = "fake@example.com"
                };

                await service.AddItemAsync(new TodoItemDto
                {
                    Title = "Testing?"
                }, fakeUser);
            }
            // Use a separate context to read data back from the "DB"
            using (var context = new ApplicationDbContext(options))
            {
                var itemsInDatabase = await context
                    .Items.CountAsync();
                Assert.Equal(1, itemsInDatabase);

                var item = await context.Items.FirstAsync();
                Assert.Equal("Testing?", item.Title);
                Assert.Equal(false, item.IsDone);

                //Item should be due 3 days from now (give or take a second)
               // var difference = DateTimeOffset.Now.AddDays(3) - item.DueAt;
               // Assert.True(difference < TimeSpan.FromSeconds(1));
            }
        }

        [Fact]
        public void MarkDoneAsComplete()
        {

            var option = new DbContextOptionsBuilder<ApplicationDbContext>().UseInMemoryDatabase(databaseName:"test").Options;


            //创建数据库上下文
            using (var context = new ApplicationDbContext(option))
            {
                var service = new TodoItemService(context);
                //先插入一个用户


                //创建一个用户

                Guid  id = Guid.NewGuid();
                ApplicationUser user = new ApplicationUser()
                {
                    Id = id,

                }
              


            }
            
        }
    }
}
